package org.cp.service.admin.impl;

import org.apache.log4j.Logger;
import org.cp.dao.admin.IRoomDAO;
import org.cp.service.admin.IRoomService;
import org.cp.vo.Room;

public class RoomServiceImpl implements IRoomService {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(RoomServiceImpl.class);

	IRoomDAO roomDAO;

	/**
	 * @return the roomDAO
	 */
	public IRoomDAO getRoomDAO() {
		return roomDAO;
	}

	/**
	 * @param roomDAO
	 *            the roomDAO to set
	 */
	public void setRoomDAO(IRoomDAO roomDAO) {
		this.roomDAO = roomDAO;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.cp.service.admin.impl.IRoomService#openK8Room1()
	 */
	public boolean openK8Room1() {
		return roomDAO
				.updateRoomByHql("update Room set state1=0 where stateid=1") == 1 ? true
				: false;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.cp.service.admin.impl.IRoomService#openK8Room2()
	 */
	public boolean openK8Room2() {
		return roomDAO
				.updateRoomByHql("update Room set state2=0 where stateid=1") == 1 ? true
				: false;

	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.cp.service.admin.impl.IRoomService#openK8Room3()
	 */
	public boolean openK8Room3() {
		return roomDAO
				.updateRoomByHql("update Room set state3=0 where stateid=1") == 1 ? true
				: false;

	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.cp.service.admin.impl.IRoomService#openD3Room1()
	 */
	public boolean openD3Room1() {
		return roomDAO
				.updateRoomByHql("update Room set d3state1=0 where stateid=1") == 1 ? true
				: false;

	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.cp.service.admin.impl.IRoomService#openD3Room2()
	 */
	public boolean openD3Room2() {
		return roomDAO
				.updateRoomByHql("update Room set d3state2=0 where stateid=1") == 1 ? true
				: false;

	}

	public boolean closeD3Room1() {
		return roomDAO
				.updateRoomByHql("update Room set d3state1=1 where stateid=1") == 1 ? true
				: false;
	}

	public boolean closeD3Room2() {
		return roomDAO
				.updateRoomByHql("update Room set d3state2=1 where stateid=1") == 1 ? true
				: false;

	}

	public boolean closeK8Room1() {
		return roomDAO
				.updateRoomByHql("update Room set state1=1 where stateid=1") == 1 ? true
				: false;
	}

	public boolean closeK8Room2() {
		return roomDAO
				.updateRoomByHql("update Room set state2=1 where stateid=1") == 1 ? true
				: false;
	}

	public boolean closeK8Room3() {
		return roomDAO
				.updateRoomByHql("update Room set state3=1 where stateid=1") == 1 ? true
				: false;
	}

	public Room getRoomState() {
		return (Room) roomDAO.listRoom().get(0);
	}
}
